package com.yanghang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanghang.dao.ComputerDao;
import com.yanghang.entity.Computer;
import com.yanghang.service.ComputerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("cs")
public class ComputerServiceImpl implements ComputerService {
    @Autowired
    private ComputerDao cd;

    @Override
    public List<Computer> selectAllComputer() {
        return cd.selectList(null);
    }

    @Override
    public List<Computer> selectComputerByLike(String name) {
        QueryWrapper<Computer> qw=new QueryWrapper<>();
        qw.like("name",name);
        return cd.selectList(qw);
    }

    @Override
    public List<Computer> selectByPrice(double minPrice, double maxPrice) {
        QueryWrapper<Computer>queryWrapper=new QueryWrapper<>();
        queryWrapper.between("price",minPrice,maxPrice);
        return cd.selectList(queryWrapper);
    }

    @Override
    public PageInfo<Computer> selectByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Computer> computers = cd.selectList(null);
        return new PageInfo<>(computers);
    }
}
